<template>
	<a-card :bordered="false" :body-style="{ 'padding-bottom': '0px' }" class="mb-2">
		<a-form ref="formRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
			<a-row :gutter="24">
				<a-col :span="8">
					<a-form-item label="名称关键词" name="searchKey">
						<a-input
							v-model:value="searchFormState.searchKey"
							placeholder="请输入仓库名称关键词"
							@keyup.enter="table.refresh(true)"
						></a-input>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-button type="primary" @click="table.refresh(true)">查询</a-button>
					<a-button style="margin: 0 8px" @click="() => formRef.resetFields()">重置</a-button>
				</a-col>
			</a-row>
		</a-form>
	</a-card>
	<a-card :bordered="false">
		<s-table
			ref="table"
			table-id="SYS_WAREHOUSE_TABLE"
			:columns="columns"
			:data="loadData"
			:alert="options.alert.show"
			bordered
			:row-key="(record) => record.id"
			:tool-config="toolConfig"
			:row-selection="options.rowSelection"
		>

			<template #operator>
				<a-space>
					<a-button type="primary" @click="form.onOpen()">
						<template #icon><plus-outlined /></template>
						新增模块
					</a-button>
          <data-export buttonName="导出用户" @dataExport="dataExportUser" />
					<batch-delete
						title="确定要删除选中模块吗?"
						buttonName="删除模块"
						:selectedRowKeys="selectedRowKeys"
						@batchDelete="deleteBatchModule"
					/>
				</a-space>
			</template>
			<template #bodyCell="{ column, record }">
        <template v-if="column.key === 'warehousetype'">
        <span >
          <a-tag color="purple">
            {{ record.warehousetype }}
          </a-tag>
        </span>
      </template>

				<template v-if="column?.dataIndex === 'icon'">
					<a-tag :color="record.color">
						<component :is="record.icon" />
					</a-tag>
				</template>
				<template v-if="column?.dataIndex === 'action'">
					<a-space>
						<a @click="form.onOpen(record)">编辑</a>
						<a-divider type="vertical" />
						<a-popconfirm title="确定要删除此模块吗？" @confirm="deleteModule(record)">
							<a-button type="link" danger size="small">删除</a-button>
						</a-popconfirm>
					</a-space>
				</template>
			</template>
     

		</s-table>
  
	</a-card>
<Form ref="form" @successful="table.refresh(true)" /> 
</template>

<script setup name="warehouse">
	import { message } from 'ant-design-vue'
	import Form from './form.vue'
  import warehouseapi from '@/api/wms/warehouse/warehouseapi'

	let searchFormState = reactive({})
	const formRef = ref()
	const table = ref()
	let form = ref()
  
	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
	const columns = [
		{
			title: '仓库编号',
			dataIndex: 'warehousecode',
       key:'warehousecode'
		},
		{
			title: '仓库名称',
			dataIndex: 'warehousename',
       key:'warehousename'
		},
		{
			title: '位置',
			dataIndex: 'address',
       key:'address'
		},
		{
			title: '仓库类型',
			dataIndex: 'warehousetype',
      key:'warehousetype'
		},
    {
			title: '负责人',
			dataIndex: 'person',
       key:'person'
		},
    {
			title: '面积',
			dataIndex: 'area',
       key:'area',
			sorter: true
		},
		{
			title: '操作',
			dataIndex: 'action',
			align: 'center',
			width: '200px'
		}
	]


	let selectedRowKeys = ref([])
	// 列表选择配置
	const options = reactive({
		alert: {
			show: true, //显示选择多少个
			clear: () => {
				selectedRowKeys = ref([])
			}
		},
		rowSelection: {
			onChange: (selectedRowKey, selectedRows) => {
				selectedRowKeys.value = selectedRowKey
			}
		}
	})


	const loadData = (parameter) => {
	 return warehouseapi.getwarehouse({parameter}).then(res=>{
      return res
    })
	}
	// 删除
	const deleteModule = (record) => {
		let params = [
			{
				id: record.id
			}
		]
		moduleApi.moduleDelete(params).then(() => {
			table.value.refresh(true)
		})
	}

	// 批量删除
	const deleteBatchModule = (params, callback) => {
		moduleApi
			.moduleDelete(params)
			.then(() => {})
			.finally(() => {
				table.value.clearRefreshSelected()
				callback() //调用组件中的回调方法
			})
	}

  const dataExportUser=(callback)=>{
    warehouseapi.Export({}).then(res=>{
      callback(res)
      message.success('导出成功')
    }).catch(res=>{
      callback(null)
      message.error('导出失败')
    })
  }





</script>
